Skip to content

fix(agents): await realtime auto tool reply in RunResult#5702

Open
longcw wants to merge 2 commits into
mainfrom
longc/fix-runresult-await-auto-tool-reply
Open

fix(agents): await realtime auto tool reply in RunResult#5702
longcw wants to merge 2 commits into
mainfrom
longc/fix-runresult-await-auto-tool-reply

Conversation

@longcw
Copy link
Copy Markdown
Contributor

@longcw longcw commented May 11, 2026

Summary

When auto_tool_reply_generation=True, the realtime model produces the tool reply via its own generation_created event after tools execute. The new SpeechHandle was created in _on_generation_created but never registered with the active RunResult, so await sess.run(...) could return before the auto reply had been spoken.

Install a placeholder future before pushing tool outputs (the model can emit the new generation during/right after update_chat_ctx), register a watcher task with RunResult, and resolve the placeholder in _on_generation_created while attaching the new handle to the run. Release the placeholder on the update_chat_ctx failure path so the run does not block for the timeout when no reply will arrive. A 5s timeout backstops cases where the model never generates a reply.

Closes #5638

longcw added 2 commits May 11, 2026 11:44
When `auto_tool_reply_generation=True`, the realtime model produces the
tool reply via its own `generation_created` event after tools execute.
The new `SpeechHandle` was created inside `_on_generation_created` and
never registered with the active `RunResult`, so `await sess.run(...)`
could return before the auto reply had been spoken.

Install a placeholder future right before pushing tool outputs (the
model can emit the new generation during/right after `update_chat_ctx`),
register a watcher task with the RunResult, and resolve the placeholder
in `_on_generation_created` while attaching the new handle to the run.
Release the placeholder on the `update_chat_ctx` failure path so the
run does not block for the timeout when no reply will arrive. A 30s
timeout backstops cases where the model never generates a reply.

Closes #5638
@chenghao-mou chenghao-mou requested a review from a team May 11, 2026 04:53
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RunResult drops post-tool reply messages when LLM has auto_tool_reply_generation=True

1 participant